#!/usr/bin/perl
use strict;
use DBI;

# load config
if(-f "$ENV{HOME}/.bictransfer") {
	{ package Settings; do "$ENV{HOME}/.bictransfer" }
}
if (!defined %Settings::db) {
    print "\n\tERROR: Config file error - could not load config settings\n\n"; exit 33;
} 

my $tarchiveID = $ARGV[0];
unless($tarchiveID) {
	print "Usage: $0 <TarchiveID>\n";
	exit(1);
}

my $dbh = DBI->connect(&Settings::dbiConnect()) or die "Failed to connect to tarchive db";

my $sth = $dbh->prepare("SELECT ArchiveLocation FROM tarchive WHERE TarchiveID=".$dbh->quote($tarchiveID));
$sth->execute();

if($sth->rows > 0) {
	my @row = $sth->fetchrow_array();
	$sth->finish();
	
	$dbh->do("DELETE FROM tarchive WHERE TarchiveID=".$dbh->quote($tarchiveID));
	
	unlink($row[0]);
}

$dbh->disconnect();
